<?php
/**
 * @version   $Id: xml.php 43 2011-01-21 08:16:25Z happy_noodle_boy $
 * @package   JCE
 * @copyright Copyright (C) 2009 Ryan Demmer. All rights reserved.
 * @license   GNU/GPL
 * This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */

/**
 * JCE Component Helper Class
 * @author ryandemmer
 */
class WFComponentHelper
{
	/*
	 * Get the JCE Component
	 * @return Component object
	 */
	function getComponent() 
	{
		static $component;

		if (!is_object($component)) {
			if (WF_JOOMLA15) {
				$component = JComponentHelper::getComponent('com_jce');
			} else {
				$db =& JFactory::getDBO();
				
				$query = 'SELECT extension_id AS id, element AS "option", params, enabled'
				. ' FROM #__extensions'
				. ' WHERE type = ' . $db->Quote('component')
				. ' AND element = ' . $db->Quote('com_jce')
				;
				
				$db->setQuery($query);
				$component = $db->loadObject();
			}
		}

		return $component;
	}
	
	/*
	 * Get the JCE Component Table Object
	 */
	function getTable()
	{
		if (WF_JOOMLA15) {
			// get component table
			$row =& JTable::getInstance('component');	
			$row->loadByOption('com_jce');
		} else {
			// get component table
			$row =& JTable::getInstance('extension');
			
			$id = $row->find(array(
				'type'		=> 'component',
				'element' 	=> 'com_jce'
			));
			
			$row->load($id);
		}
		
		return $row;
	}
}